Queues - Ting Wong - Recursion Tracing#34
Conversation
| This means that the recursion is calling itself infinitely and a solution can't be reached (or that no solution is possible). | ||
|
|
||
| - Tail Recursion | ||
| I think that tail recursion means that rather than performing all your recursion calls first before returning back to calculate the results, you first perform all your calculations then move to the next recursive step. In this way, some efficiency is gained as you don't need to go through the activation chain all over again to perform the recursion. |
There was a problem hiding this comment.
I didn't go over this in class, but this is mostly right. I may cover in the future, but it's not terribly important at this moment.
| else | ||
| return (n%10) + mystery2(n/10) | ||
| end | ||
| end |
There was a problem hiding this comment.
Hmm... This will definitely change the behavior of what the method does, but perhaps I should have specified what "the way we might expect it to work" is. I wold expect mystery2(-123) to produce -6 not 6. If you expected 6, then your solution is correct. If you wanted -6, then it's not.
| end | ||
| end | ||
| end | ||
| ``` |
There was a problem hiding this comment.
Nice job! A couplet things to consider here.
-
Regex would make this potentially a more sophisticated solution, but yours is maybe easier to read.
-
Is your assumption that we would want to strip out all non-alpha characters? That's what your solution would produce ==> mystery5("Hi, there!") would be "*******", but what if we wanted it to be "**, *****!" which is what I intended. I will make these instructions more clear for my next iteration of this assignment.
Recursion TracingLooks good! |
Recursion Tracing
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions